/* SPDX-License-Identifier: GPL-2.0 */
/*
 * -*- mode: c; c-basic-offset: 8; -*-
 * vim: noexpandtab sw=8 ts=8 sts=0:
 *
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

#ifndef FSQOS_H
#define FSQOS_H

#include <linux/semaphore.h>

#include "ocfs2.h"

/* Error define */
#define ESIZE 1 /* Illegal IO size */
#define ETOUT 2 /* Getting token timeout */
#define ENQOS 3 /* QoS module is not initialized */
#define RETRY 5 /* Token is not enough,retry */


struct o2qos_token_region {
	long qos_generation;
	struct task_struct *token_task;
	spinlock_t lock;
	unsigned long token_speed_limit;
	unsigned long long token_capacity;
	unsigned int token_period;  /* the period of creating token */
	atomic64_t token_available;  /* number of block or 512 bytes */
	struct semaphore sem;
};

int init_o2qos(struct super_block *sb);
void exit_o2qos(struct ocfs2_super *osb);
int ocfs2_get_qos_token(struct super_block *sb, int size, unsigned int timeoutMs);
int ocfs2_check_unmap_available(struct ocfs2_super *osb);

#endif
